﻿function unselectRestRows() {
    if ($(this).hasClass('hiddenRow')) {
        $(this).hide();
    }
    else {
        if ($(this).hasClass('selectedRow')) {
            $(this).children('.selected').removeClass('selected');
            $(this).prev().prev().children('td.center').removeClass('onTopSelected');
            $(this).children('.onMouseOver').removeClass('onMouseOver');
            $(this).removeClass('selectedRow');
        }
    }
}
$(function () {
    $('.mGrid td.center:first-child').mouseover(function () {
        if ($(this).hasClass('selected') == false) {
            $(this).addClass('onMouseOver');
        }
    });
    $('.mGrid td.center:first-child').mouseout(function () {
        if ($(this).hasClass('selected') == false) {
            $(this).removeClass('onMouseOver');
        }
    });

    $('.pagerclass td').mouseout(function () {
        if ($(this).hasClass('currentFrame') == false) {
            $(this).removeClass('onMouseOver');
        }
    });

    $('.pagerclass td').mouseover(function () {
        if ($(this).hasClass('currentFrame') == false) {
            $(this).addClass('onMouseOver');
        }
    });


    $('.mGrid td.center:first-child').click(function () {
        var currRow = $(this).parent();
        if (currRow.hasClass('hiddenRow') == false) {
            // Unselect Row
            if ($(this).hasClass('selected')) {
                $(this).removeClass('selected');
                currRow.removeClass('selectedRow')
                currRow.next().hide();
            }
            // Select Row
            else {
                $('.mGrid tr').each(unselectRestRows);
                currRow.addClass('selectedRow');
                $(this).addClass('selected');
                if (currRow.prev() != null) {
                        currRow.prev().prev().children('td.center').addClass('onTopSelected');
                }
                currRow.next().show();
            }
        }
    });
});
